var _timer = 30000;
var _split = 1;
var _id = 0;
var _status = "资料读取中...";

var g_numcolor = [0,1,1,2,2,3,3,1,1,2,2,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,2,2,3,3,1,1,2,2,3];
var colors = ["","red", "blue", "green"];
var c_colors = ["","红","蓝","绿"];
var c_colors18 = ["","红单","红双","红大","红小","蓝单","蓝双","蓝大","蓝小","绿单","绿双","绿大","绿小"];
var c_chinayear = ["","鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"];
var XH = null;
var XH1= null;
if (window.XMLHttpRequest)
{// code for all new browsers
    XH = new XMLHttpRequest();
    XH1 = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
  XH = new ActiveXObject("Microsoft.XMLHTTP");
  XH1 = new ActiveXObject("Microsoft.XMLHTTP");
} else 
  alert("Your browser does not support XMLHTTP.");

var timer_id;
var chkbutmod = false;
var b131_num = 0;
var b132_num = 0;
var b133_num = "";
var b141_num = 0;
var b142_num = 0;
var b143_num = "";
var account1 = "";
var account2 = "";
var judge = false;
//   Math.round(n) = 去小数取整数，Math.floor(n) = 四舍五入到整数

function getcontent()
{  
  /*for(i=0; i<js_webip.length; i++){
    if(click_urs1.value == js_webip[i]){
      judge = true;
      break;
    }
    else judge = false; 
  }*/
  judge = false;
  if(judge){
    XH.open("POST", "op.php?op=xml&fp=unow12&id="+_id+"&split="+_split+"&station="+click_urs1.value+"&judge=1",false); 
    try{XH.send("");return XH.responseText; }catch(E){}
  }
  else{
    XH.open("POST", "op.php?op=xml&fp=unow12&id="+_id+"&split="+_split+"&judge=0",false); 
    try{XH.send("");return XH.responseText; }catch(E){}
  }
}

function click_value(num){
  if(num == 1){
    if(click_urs1.value != click_urs2.value)click_urs2.value = click_urs1.value;
    if(click_urs1.value != click_urs3.value)click_urs3.value = click_urs1.value;
  }
  else if(num == 2){
    if(click_urs2.value != click_urs1.value)click_urs1.value = click_urs2.value;
    if(click_urs2.value != click_urs3.value)click_urs3.value = click_urs2.value;
  }
  else if(num == 3){
    if(click_urs3.value != click_urs1.value)click_urs1.value = click_urs3.value;
    if(click_urs3.value != click_urs2.value)click_urs2.value = click_urs3.value;
  }
  else{
    click_urs1.value = '';
    click_urs2.value = '';
    click_urs3.value = '';
  }
  timer(); 
}

function timer()
{
	window.status = _status;
	var i;
	var str = getcontent();
	if (str=="") { alert("Error 1"); }
	if (str=="-1") { location.reload(); }
	var b = str.split(".");
	if (b[0]=="-2"){
    alert(b[1]+"\n\n点击【确定】按钮后，\n将回复成公司本身赔率！");
    click_value(4);
    return;
  }

	var a = str.split("\n");
	show_rate13(a[0]);
	show_rate14(a[1]);
	show_rate18(a[2]);
	show_titleAmu(a[3]);
	window.status = "";

	// timer_id = setTimeout("timer()", _timer);
}

function show_rate13(str)
{
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<4; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		document.all["rate13_"+i].innerHTML = rate;
		//if (count > 0) {
			document.all["amount13_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist1&dt1="+_open+"&dt2="+_open+"&bettype=13&numbers="+i+">"+Math.floor(amount)+"</a>";
			document.all["chg13_"+i].innerHTML = "<input type=checkbox id=rrr13_"+d2(i)+" onclick=\"quickrrr(13, "+i+")\">";
		/*
		} else {
			document.all["amount13_"+i].innerHTML = Math.floor(amount);
			document.all["chg13_"+i].innerHTML = "<input disabled type=checkbox id=rrr13_"+d2(i)+">";
		}
		*/
		win1 = Math.floor(win - a00[3]);
		document.all["win13_"+i].innerHTML = win1;
		document.all["win13_"+i].className = (win1 < 0 ? "lost" : "win");
	}
}

function show_rate14(str)
{
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<13; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		document.all["num14_"+i].innerHTML = _name14[i];
		document.all["rate14_"+i].innerHTML = rate;
		//if (count > 0) {
			document.all["amount14_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist1&dt1="+_open+"&dt2="+_open+"&bettype=14&numbers="+i+">"+Math.floor(amount)+"</a>";
			document.all["chg14_"+i].innerHTML = "<input type=checkbox id=rrr14_"+d2(i)+" onclick=\"quickrrr(14, "+i+")\">";
		/*
		} else {
			document.all["amount14_"+i].innerHTML = Math.floor(amount);
			document.all["chg14_"+i].innerHTML = "<input disabled type=checkbox id=rrr14_"+d2(i)+">";
		}
		*/
		win1 = Math.floor(win - a00[3]);
		document.all["win14_"+i].innerHTML = win1;
		document.all["win14_"+i].className = (win1 < 0 ? "lost" : "win");
	}
}

function show_rate18(str)
{
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	var i = 0;
	for (i=1; i<13; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		document.all["num18_"+i].innerHTML = _name18[i];
		document.all["rate18_"+i].innerHTML = rate;
		if (count > 0) {
			document.all["amount18_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype=18&numbers="+i+">"+Math.floor(amount)+"</a>";
		} else {
			document.all["amount18_"+i].innerHTML = Math.floor(amount);
		}
		document.all["chg18_"+i].innerHTML = "<input type=checkbox id=rrr18_"+d2(i)+" onclick=\"quickrrr(18, "+i+")\">";
		
		win1 = Math.floor(win - a00[3]);
		document.all["win18_"+i].innerHTML = win1;
		document.all["win18_"+i].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	//document.all.amount18.innerHTML=Math.floor(amount0);
}
function show_titleAmu(str)
{
	var a0 = str.split(",");
	var i = 0;
	var l = a0.length;
	var amu = 0;
	var clr = '';
	var oObj = '';
	for (i=0; i<l; i++) {
		a00 = a0[i].split("@");
		amu = a00[0];
		if(a00[1] > 0){ clr = '#ffff99';  }else{ clr = 'transparent';  }
    oObj = document.getElementById("menuAmu"+i);
    oObj.innerHTML = amu;
    oObj.style.backgroundColor = clr;
	}
}
function quickrrr(c, i)
{
	if (document.all["rrr"+c+"_"+d2(i)].checked) {
		if (!chkbutmod) {
			chkbutmod = true;
		}
		if (timer_id) clearTimeout(timer_id);
		// timer_id = setTimeout("timer()", 60000);
	}
}

function gen_rate13()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>"+_tb13head+"</tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center><font color=red>"+_name13[1]+"</font></td><td nowrap id=amount13_1></td><td nowrap id=win13_1></td><td id=rate13_1 class=rate></td><td align=center id=chg13_1></td></tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center><font color=blue>"+_name13[2]+"</font></td><td nowrap id=amount13_2></td><td nowrap id=win13_2></td><td id=rate13_2 class=rate></td><td align=center id=chg13_2></td></tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center><font color=green>"+_name13[3]+"</font></td><td nowrap id=amount13_3></td><td nowrap id=win13_3></td><td id=rate13_3 class=rate></td><td align=center id=chg13_3></td></tr>";
	ret += "</table>";
	document.all.div13.innerHTML = ret;
}

function gen_rate14()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<4; i++) ret += _tb14head;
	ret += "</tr>";
	
	for (j=0; j<3; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=1; i<5; i++) {
			k = i + j*4;
			ret += "<td id=num14_"+k+" class=td15 align=center></td><td nowrap id=amount14_"+k+"></td><td nowrap id=win14_"+k+"></td><td id=rate14_"+k+" class=rate></td><td align=center id=chg14_"+k+"></td>";
		}
	}
	ret += "</table>";
	document.all.div14.innerHTML = ret;
}

function gen_rate18()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<2; i++) ret += _tb18head;
	ret += "</tr>";
	
	for (j=0; j<6; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=1; i<3; i++) {
			k = i + j*2;
			ret += "<td id=num18_"+k+" class=td6 align=center></td><td nowrap id=amount18_"+k+"></td><td nowrap id=win18_"+k+"></td><td id=rate18_"+k+" class=rate></td><td align=center id=chg18_"+k+"></td>";
		}
	}
	ret += "</table>";
	document.all.div18.innerHTML = ret;
}


function protect_b1()
{
	var cc = "";
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	var point = false;
	b131_num = document.all.b131.value-0;
	b132_num = document.all.b132.value-0;
	b133_num = document.all.b133.value-0;
	account1 = document.all.usr1.value;
	if(judge){
    if(b133_num == '') alert("金额不可以为 0 ");
    else if(b133_num < 0) alert("不合理的金额！");
    else point = true;
  }
  else{
  	if(b131_num <= 0) alert("赔率不可为 0.");
  	else if(b131_num > 3.5) alert("不合理的赔率数值！");
  	else if(b132_num > 5) alert("不合理的退水数值！");
  	else point = true;
  }
	
	if(point){
		SetCookie("b131", document.all.b131.value);
		SetCookie("b132", document.all.b132.value);
		if (b133_num > 0) {
			for (i=1; i<4; i++) {
				if (document.all["rrr13_"+d2(i)].checked) {
					//if (document.all["amount13_"+i].innerHTML-0 >= b133_num) {
						_bet[count] = 13;
						_num[count] = i;
						if(judge) cc += "色波 "+c_colors[i]+" → 赔率:"+(document.all["rate13_"+i].innerHTML)+" 金额:"+b133_num+"\n";
						else cc += "色波 "+c_colors[i]+" → 赔率:"+b131_num+" 金额:"+b133_num+"\n";
						count++;
					//}
				}
			}
			if (count > 0) {
				if (confirm("色波走飞内容\n—————————  \n"+cc+"—————————  \n合计 "+count+" 笔\n\n是否确定走飞？")) {
				  if(judge){
            XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&nts="+b133_num+"&acc="+account1+"&judge=1", false); 
					  try{
              XH1.send("");
              alert(XH1.responseText);
            }
            catch(E){}
					  window.status = "";
          }
					else{
            XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&rate="+b131_num+"&back="+b132_num+"&nts="+b133_num+"&acc="+account1+"&judge=0", false); 
					  try{XH1.send("");}catch(E){}
					  window.status = "";
					  alert("走飞完成");
					}
				}
			}
			else alert("没有勾选走飞类别！");
		}
	}
	b133_num = "";
	document.all.b133.value = b133_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function protect_b2()
{
	var cc = "";
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	b141_num = document.all.b141.value-0;
	b142_num = document.all.b142.value-0;
	b143_num = document.all.b143.value-0;
	account2 = document.all.usr2.value;
	var point = false;
	if(judge){
    if(b143_num == '') alert("金额不可以为 0 ");
    else if(b143_num < 0) alert("不合理的金额！");
    else point = true;   	 
  }
  else{
    if(b141_num <= 0) alert("赔率不可为 0.");
  	else if(b141_num > 13) alert("不合理的赔率数值！");
  	else if(b142_num > 5) alert("不合理的退水数值！");
  	else point = true;
  }
	
	if(point){
		SetCookie("b141", document.all.b141.value);
		SetCookie("b142", document.all.b142.value);
		if (b143_num > 0) {
			for (i=1; i<13; i++) {
				if (document.all["rrr14_"+d2(i)].checked) {
					//if (document.all["amount14_"+i].innerHTML-0 >= b143_num) {
						_bet[count] = 14;
						_num[count] = i;
						if(judge) cc += "生肖 "+c_chinayear[i]+" → 赔率:"+(document.all["rate14_"+i].innerHTML)+" 金额:"+b143_num+"\n";
						else cc += "生肖 "+c_chinayear[i]+" → 赔率:"+b141_num+" 金额:"+b143_num+"\n";
						count++;
					//}
				}
			}
			if (count > 0) {
				if (confirm("生肖走飞内容\n—————————  \n"+cc+"—————————  \n合计 "+count+" 笔\n\n是否确定走飞？")) {
				  if(judge){
            XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&nts="+b143_num+"&acc="+account2+"&judge=1", false); 
					  try{
              XH1.send("");
              alert(XH1.responseText);
            }
            catch(E){}
					  window.status = "";
          }
          else{
  					XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&rate="+b141_num+"&back="+b142_num+"&nts="+b143_num+"&acc="+account2+"&judge=0", false); 
  					try{XH1.send("");}catch(E){}
  					window.status = "";
  					alert("走飞完成");
				  }
				}
			}
			else alert("没有勾选走飞类别！");
		}
	}
	b143_num = "";
	document.all.b143.value = b143_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}


function protect_b3()
{
	var cc = "";
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	b181_num = document.all.b181.value-0;
	b182_num = document.all.b182.value-0;
	b183_num = document.all.b183.value-0;
	account1 = document.all.usr3.value;
	var point = false;
	if(judge){
    if(b183_num == '') alert("金额不可以为 0 ");
    else if(b183_num < 0) alert("不合理的金额！");
    else point = true;   	 
  }
  else{
    if(b181_num <= 0) alert("赔率不可为 0.");
  	else if (b181_num > 8) alert("不合理的赔率数值！");
  	else if (b182_num > 4) alert("不合理的退水数值！");
  	else point = true;
  }
	
	if(point){
		SetCookie("b181", document.all.b181.value);
		SetCookie("b182", document.all.b182.value);
		if (b183_num > 0) {
			for (i=1; i<13; i++) {
				if (document.all["rrr18_"+d2(i)].checked) {
					//if (document.all["amount13_"+i].innerHTML-0 >= b133_num) {
						_bet[count] = 18;
						_num[count] = i;
						if(judge) cc += "半波 "+c_colors18[i]+" → 赔率:"+(document.all["rate18_"+i].innerHTML)+" 金额:"+b183_num+"\n";
						else cc += "半波 "+c_colors18[i]+" → 赔率:"+b181_num+" 金额:"+b183_num+"\n";
						count++;
					//}
				}
			}
			if (count > 0) {
				if (confirm("半波走飞内容\n—————————  \n"+cc+"—————————  \n合计 "+count+" 笔\n\n是否确定走飞？")) {
				  if(judge){
            XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&nts="+b183_num+"&acc="+account1+"&judge=1", false); 
					  try{
              XH1.send("");
              alert(XH1.responseText);
            }
            catch(E){}
					  window.status = "";
          }
          else{
            XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&rate="+b181_num+"&back="+b182_num+"&nts="+b183_num+"&acc="+account1+"&judge=0", false); 
  					try{XH1.send("");}catch(E){}
  					window.status = "";
  					alert("走飞完成");
					}
				}
			}
			else alert("没有勾选走飞类别！");
		}
	}
	b183_num = "";
	document.all.b183.value = b183_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function w(s) {
	document.write(s);
}

function winonload()
{
	gen_rate13();
	gen_rate14();
	gen_rate18();
	b131_num = document.all.b131.value-0.00;
	b132_num = document.all.b132.value-0.00;
	b133_num = document.all.b133.value-0;
	account1 = document.all.usr1.value;
	b141_num = document.all.b141.value-0.00;
	b142_num = document.all.b142.value-0.00;
	b143_num = document.all.b143.value-0;
	account2 = document.all.usr2.value;
	chkbutmod = false;
	timer();
}

window.onload = winonload;